package com.project.dao.impl;

import com.project.bean.UserBean;
import com.project.dao.UserDao;

import java.time.LocalDate;

public class UserDaoImpl extends BaseDao implements UserDao {

    @Override
    public UserBean lang(String userName, String pwd) {
        UserBean user = new UserBean();
//        链接
        this.setConnection();
        try {
//            执行sql语句
            ps=con.prepareStatement("select * from t_users where u_name=? and u_password=?");
//            占位符
            ps.setObject(1,userName);
            ps.setObject(2,pwd);
//            结果集
            res=ps.executeQuery();
//            循环加入
            while (res.next()){
                user.setId(res.getInt("pk_usersId"));
                user.setUserName(res.getString("u_name"));
                user.setPassword(res.getString("u_password"));
            }
//            关闭流
            this.closeConnection();

        } catch (Exception e) {
            e.printStackTrace();
        }
        if (user.getUserName()!=null){
            return user;
        }
        return null;
    }

}
